;; Copyright (c) [2022] [bobwxc]
;; This file is licensed under Mulan PubL v2.
;; You can use this software according to the terms and conditions of the Mulan PubL v2.
;; You may obtain a copy of Mulan PubL v2 at:
;;          http://license.coscl.org.cn/MulanPubL-2.0
;; THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
;; EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
;; MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
;; See the Mulan PubL v2 for more details.

(in-package #:cl-mdb)

(defparameter *node-id*
  0
  "machine node id")

(defstruct row
  (content nil :type (or number character string sequence null))
  (original-key nil :type (or string null))
  (uuid nil :type (or string null))
  (time 0 :type number) ;; last insert or update time
  (operation-id  nil :type (or number null)) ;; last insert or update or remove operation id
  (read-flag nil :type boolean)
  (write-flag nil :type boolean)
  (remove-flag nil :type boolean)
  )

(defun generate-row (key value &optional counter)
  (let ((r (make-row :content value
                     :original-key key
                     :time (get-universal-time)
                     :operation-id (snid:genid *node-id* counter)
                     :read-flag nil
                     :write-flag nil)))
    r))


(defun init-store-list ()
  '())

(defun push-value (store-list key value)
  (push (generate-row key value 0)
        store-list)
  store-list)

(defun insert-value (store-list key value)
  (push-value store-list key value))

